import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { VerifyService } from '../../services/admin/verify.service';

/**
 * VerifyController
 * 对应 PHP: Verify Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('verify')
@Controller('adminapi/verify')
export class VerifyController {
  constructor(private readonly verifyService: VerifyService) {}

  /**
   * 核销记录
   * 路由: GET verify/record
   * PHP路由: Route::get('verify/record', 'verify.Verify/lists')
   */
  @Get('verify/record')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销记录' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.verifyService.getPage(data);
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * 核销记录
   * 路由: GET verify/:verify_code
   * PHP路由: Route::get('verify/:verify_code', 'verify.Verify/detail')
   */
  @Get('verify/:verify_code')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销记录' })
  async detail(
    @Param('verify_code') verify_code: string,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: detail

      return await this.verifyService.getDetail(verify_code);
    } catch (error) {
      throw new BusinessException('detail操作失败', error);
    }
  }

  /**
   * 核销记录
   * 路由: POST verify/:verify_code
   * PHP路由: Route::post('verify/:verify_code', 'verify.Verify/verify')
   */
  @Post('verify/:verify_code')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销记录' })
  async verify(
    @Param('verify_code') verify_code: string,
    @Body() data: VerifyDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: verify

      return await this.verifyService.verify(verify_code);
    } catch (error) {
      throw new BusinessException('verify操作失败', error);
    }
  }

  /**
   * 核销记录
   * 路由: GET detail/:verify_code
   * PHP路由: Route::get('detail/:verify_code', 'verify.Verify/getInfoByCode')
   */
  @Get('detail/:verify_code')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '核销记录' })
  async getInfoByCode(
    @Param('verify_code') verify_code: string,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getInfoByCode

      return await this.verifyService.getInfoByCode(verify_code);
    } catch (error) {
      throw new BusinessException('getInfoByCode操作失败', error);
    }
  }
}
